import 'package:flutter/material.dart';

main() => runApp(MaterialApp(home: MyApp(),));

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  bool _enabled = false;

  @override
  Widget build(BuildContext context) {
    var _onPressed;
    if (_enabled) {
      _onPressed = () {
        print('tap');
      };
    }    

    return Scaffold(
      appBar: AppBar(
        title: Text('toggle button'),
      ),
      body: ListView(
        children: <Widget>[
          ListTile(
            title: new RaisedButton(
              child: Text('Click me'),
              onPressed: _onPressed,
            ),
          ),
          SwitchListTile(
            value: _enabled,
            onChanged: (bool value) {
              setState(() {
               _enabled = value; 
              });
            },
          )
        ],
      ),
    );
  }
}